package org.smr.dev.dao;

import java.util.HashMap;
import java.util.Map;

import org.smr.dev.AbstractCodeGenerator;
import org.smr.dev.CodeGenerator;
import org.smr.dev.OrmDefCreator;
import org.smr.dev.matedata.OrmDef;

public class DaoCodeGenerator implements CodeGenerator {

	
	private String javaBeanTemplateFileName;

	private String output2FilePathAndName;
	
	Map<String, Object> velocityVariables = new HashMap<String, Object>();


	public void generate(String tableName) {
		OrmDefCreator odc = new OrmDefCreator();
		OrmDef ed = odc.create(tableName);
		generate(ed);
	}

	private void generate(OrmDef od) {

		Map<String, Object> velocityVariables = new HashMap<String, Object>();
		velocityVariables.put("package", "com.weimi.elec.entities.biz");
		velocityVariables.put("tableName", od.getTableName());
		velocityVariables.put("javaBeanName", od.getEntityName());
		velocityVariables.put("MODEL_PROPERTY_VARIABLE", od.getColumnAndAttributeList());
		
		AbstractCodeGenerator ac = new AbstractCodeGenerator(javaBeanTemplateFileName, velocityVariables,
				output2FilePathAndName);
		ac.generate();
	}


	public void generate(Map<String, Object> codeVar){
		AbstractCodeGenerator ac = new AbstractCodeGenerator(javaBeanTemplateFileName, codeVar,
				output2FilePathAndName);
	}

	public DaoCodeGenerator(String javaBeanTemplateFileName, String output2FilePathAndName) {
		super();
		this.javaBeanTemplateFileName = javaBeanTemplateFileName;
		this.output2FilePathAndName = output2FilePathAndName;
	}

}
